package com.yeban.javase.day12;

import java.util.HashSet;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/10/21
 *
 * 练习1.求一个字符串"aiodjl;hriWFUADJSV123UEHiowfjnivowe"中一共有几个不重复的字母,区分大小写,如a,A算两个字符
 */
public class HashSetTest1 {

    public static void main(String[] args) {
        String str = "aiodjl;hriWFUADJSV123UEHiowfjnivowe";
        char[] ch = str.toCharArray();
        String regex = "[a-zA-Z]";
        HashSet<Character> set = new HashSet<>();
        for(char c : ch) {
            if(String.valueOf(c).matches(regex)) {
                set.add(c);
            }
        }

        /*HashSet<Character> set = new HashSet<>();
        String regex = "[^a-zA-Z]";
        str = str.replaceAll(regex, "");
        for(char c : str.toCharArray()) {
            set.add(c);
        }
        System.out.println(set);*/
        System.out.println("一共有" + set.size() + "种类型的不重复字母！");
    }
}
